from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options



class ASMS():
    def __init__(self, driver):
        self.driver = driver

    #登录
    def login(self,task_id,username,password,code):
        self.driver.find_element(By.ID,'taskId').send_keys(task_id)
        self.driver.find_element(By.ID,'loginName').send_keys(username)
        self.driver.find_element(By.ID,'password').send_keys(password)
        self.driver.find_element(By.ID,'vericode').send_keys(code)
        sleep(3)
        self.driver.find_element(By.XPATH,'//*[@id="fmedit"]/div[2]/div[6]/input').click()
        sleep(3)


    # 资产管理
    def manage(self):
        self.login()
        self.driver.find_element(By.XPATH,'//*[@id="leftmenu_asset_manage"]/div[1]/a').click()
        sleep(1)
        # 增加
        # self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/div[2]/div[2]/div/input').click() # 点击增加
        # sleep(2)
        # self.driver.find_element(By.ID, 'title').send_keys('惠普电脑') # 输入资产名称
        # self.driver.find_element(By.ID, 'providerId').click() # 点击存放地点下拉框
        # self.driver.find_element(By.XPATH, '//*[@id="providerId"]/option[2]').click()
        # self.driver.find_element(By.ID,'storageId').click() # 点击供应商
        # self.driver.find_element(By.XPATH,'//*[@id="storageId"]/option[2]').click()
        # sleep(2)
        # self.driver.find_element(By.XPATH, '//*[@id="fm_new"]/div/div[1]/div/div[1]').click()

        # 修改
        # self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/div[2]/div[3]/table/tbody/tr[2]/td[8]/a[1]').click() # 点击修改
        # sleep(2)
        # self.driver.find_element(By.ID, 'title').clear()
        # self.driver.find_element(By.ID, 'title').send_keys('戴尔电脑')  # 输入资产名称
        # self.driver.find_element(By.ID, 'providerId').click()  # 点击存放地点下拉框
        # self.driver.find_element(By.XPATH, '//*[@id="storageId"]/option[3]').click()
        # self.driver.find_element(By.ID, 'storageId').click()  # 点击供应商
        # self.driver.find_element(By.XPATH, '//*[@id="providerId"]/option[4]').click()
        # sleep(2)
        # self.driver.find_element(By.XPATH, '//*[@id="fm_new"]/div/div[1]').click()
        # 查询
        # self.driver.find_element(By.ID, 'title').clear()
        # self.driver.find_element(By.ID,'title').send_keys('惠普电脑')
        # sleep(2)
        # self.driver.find_element(By.XPATH,'//*[@id="fmsearch"]/div[3]/button').click()
        # sleep(2)
        # 查看
        self.driver.find_element(By.XPATH,'/html/body/div[2]/div/div[2]/div[2]/div[3]/table/tbody/tr[2]/td[2]/div/a').click()
        sleep(2)
    # 个人信息
    def information(self):
        self.login()

    # 供应商
    def supplier(self):
        pass
    # 存放地点
    def location(self):
        self.login()
        self.driver.find_element(By.XPATH, '//*[@id="leftmenu_asset_storage"]/div[1]/a/img').click()
        sleep(1)
        self.driver.find_element(By.ID, 'title').clear()
        self.driver.find_element(By.ID,'title').send_keys('总经理办公室')
        self.driver.find_element(By.XPATH,'//*[@id="fmsearch"]/div[3]/input').click()
        sleep(2)
if __name__ == '__main__':
    url = r'http://172.16.22.105:8080/bsams/front/login.do'
    task_id = '1'
    username = 'test01'
    password = '123456'
    code = 'shtd'
    driver = webdriver.Chrome(options=options)
    driver.get(url)
    

    asms = ASMS(driver)
    asms.login(task_id,username,password,code)
    # asms.manage()
    #asms.location()

    # self.driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/a[3]').click() # 退出
    # sleep(3)
    driver.quit()
